<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line("quickprint");?></h3>
<p class="required">Ghi chú : * Thông tin bắt buộc</p>
<style>
    .fone_num_cls{
        width:13% !important;
    }
    .btn-success,.btn-danger,.btn-primary.delete{
        vertical-align: top;
    }
    .required{color:red;}
</style>

<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" customerAssess-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open('auth/others/quickprintTemplate',array('id' => 'ajaxform'));?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //thong tin dat cho
                echo form_label($this->lang->line('booking_place_code').' <span class="required">*</span>', 'booking_place_code');
                echo form_input(array('name' => 'booking_place_code', 'id' => 'booking_place_code', 'value' => '','required'=>'required'));
                echo form_error('booking_place_code');
                //thong tin dat cho
                echo form_label($this->lang->line('sumMoney'), 'sumMoney');
                echo form_input(array('name' => 'sumMoney', 'id' => 'sumMoney', 'value' => ''));
                echo form_input(array('type'=>'hidden', 'name' => 'sumMoney_fake', 'id' => 'sumMoney_fake', 'value' => ''));
                echo form_error('sumMoney');
                //Thông tin hành khách
                echo '<div id="booking-msg">';
                echo '<div id="fone_addon1" class="fonediv">';
                
                echo form_label($this->lang->line('customersName').' <span class="required">*</span>', 'customersName');
                echo form_textarea(array('name' => 'customersName', 'id' => 'customersName', 'value' => '','rows'=>'5','placeholder'=>$this->lang->line('customersName')));
                echo form_input(array('type'=>'hidden', 'name' => 'customersName_fake', 'id' => 'customersName_fake', 'value' => ''));
                echo form_error('customersName');
                
                //NGAY BAY
                echo form_input(array('required'=>'required','id' => 'datefly', 'name' => 'datefly','value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('datefly')));
                echo form_error('datefly');
                echo ' ';
                //số hiệu
                echo form_input(array('required'=>'required','id' => 'numberfly','name' => 'numberfly', 'value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('numberfly')));
                echo form_error('numberfly');
                echo ' ';
                //Sb đi
                echo form_input(array('required'=>'required','id' => 'gosb','name' => 'gosb', 'value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('gosb')));
                echo form_error('gosb');
                echo ' ';
                //Giờ đi
                echo form_input(array('required'=>'required','id' => 'timefly','name' => 'timefly', 'value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('timefly')));
                echo form_error('timefly');
                echo ' ';
                //Sb đến
                echo form_input(array('required'=>'required','id' => 'stopsb','name' => 'stopsb', 'value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('stopsb')));
                echo form_error('stopsb');
                echo ' ';
                //Giờ đến
                echo form_input(array('required'=>'required','id' => 'timeat','name' => 'timeat', 'value' => '','class' => 'fone_num_cls','placeholder'=>$this->lang->line('timeat')));
                echo form_error('timeat');
                echo ' ';
                echo form_button(array('content' => $this->lang->line('add'),'class' => 'btn btn-success'));
                echo form_input(array('type' => 'hidden', 'name' => 'booking-info[]', 'id' => 'booking-info-1', 'value' => ''));
                echo '</div>';
                echo '</div>';
                
                //dieu kien ve
                echo form_label($this->lang->line('dkve'), 'dkve');
                echo form_textarea(array('name' => 'dkve', 'id' => 'dkve', 'value' => '','rows'=>'5'));
                echo form_error('dkve');
                //dieu kien hanh lí
                echo form_label($this->lang->line('dkhanhly'), 'dkhanhly');
                echo form_textarea(array('name' => 'dkhanhly', 'id' => 'dkhanhly', 'value' => '','rows'=>'5'));
                echo form_error('dkhanhly');
                //dieu kien
                echo form_checkbox(array('name'=>'condition_print','id'=>'condition_print','value'=>'1','checked'=>TRUE,'style'=>'vertical-align: top;')).form_label($this->lang->line('condition_print'), 'condition_print',array('style'=>'display:inline-block!important;cursor: pointer;'));
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <a href="<?php echo site_url('auth/ticketWorkers'); ?>" class="btn btn-danger"><?php echo $this->lang->line('cancel')?></a>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<?php $this->load->view('templates/backend/lib'); ?>

<script src="<?php echo base_url().'static/templates/backend/js/jquery.maskedinput.js';?>"></script>
<script src="<?php echo base_url().'static/templates/backend/js/autoNumeric.js';?>"></script>

<script>
$(document).ready(function() {
        var add_form = 2;
        $("#customersName_fake").hide();
         $( "button.btn-success" ).click(function() {
            updateURL = '/auth/getphone/infoBooking?id='+add_form;
            $.ajax(
            {
                    url : updateURL,
                    success:function(data)
                    {
                       $("#booking-msg").append(data);
                       add_form = add_form + 1;
                    },
                    error: function() 
                    {

                    }
            });
        });
        
        $(function() {
            var $datepicker = $( "#datefly" );
            $datepicker.datepicker({ dateFormat: 'dd/mm/yy' }).val();
        });
        
        $(function() {
            $.mask.definitions['a'] = "[A-Z]";
            $.mask.definitions['b'] = "[0-9]";
            $.mask.definitions['*'] = "[A-Z0-9]";

            $("#numberfly").mask("******",{placeholder:" ",autoclear:false});//SO HIEU
            $("#timefly").mask("99:99");//GIỜ BAY
            $("#gosb").mask("aaa");//SB ĐI
            $("#timeat").mask("99:99");//GIỜ ĐẾN
            $("#stopsb").mask("aaa");//SB ĐẾN

            $("input").blur(function() {
                $("#info").html("Unmasked value: " + $(this).mask());
            }).dblclick(function() {
                $(this).unmask();
            });
        });
        
        $("#timefly").blur(function() {
        var timesx=this.value;
        var times = timesx.split(":");
        if (timesx.indexOf('_',1) >0)
        {
            alert("Thời gian nhập không đúng");
            this.value='';
            $(this).focus();
        }else if (times[0] > 23 || times[1]>59)
        {
            alert("Thời gian nhập không đúng");
            this.value='';
            $(this).focus();
        }
    });
    
    $("#timeat").blur(function() {
        var timesx=this.value;
        var times = timesx.split(":");
        if (timesx.indexOf('_',1) >0)
        {
            alert("Thời gian nhập không đúng");
            this.value='';
            $(this).focus();
        }else if (times[0] > 23 || times[1]>59)
        {
            alert("Thời gian nhập không đúng");
            this.value='';
            $(this).focus();
        }
    });
    
    $("#datefly").blur(function() {
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    $("#numberfly").blur(function() {
        if(document.getElementById("numberfly").value.trim()==""){
            alert("Vui lòng nhập thông tin vào! Nhớ bật Caplock");
            $(this).focus();
            return false;
        }
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    $("#timefly").blur(function() {
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    $("#gosb").blur(function() {
        if(document.getElementById("gosb").value.trim()==""){
            alert("Vui lòng nhập thông tin vào! Nhớ bật Caplock");
            $(this).focus();
            return false;
        }
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    $("#timeat").blur(function() {
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    $("#stopsb").blur(function() {
        if(document.getElementById("stopsb").value.trim()==""){
            alert("Vui lòng nhập thông tin vào! Nhớ bật Caplock");
            $(this).focus();
            return false;
        }
        document.getElementById("booking-info-1").value = document.getElementById("datefly").value 
        + '-' + document.getElementById("numberfly").value.trim()
        + '-' + document.getElementById("timefly").value
        + '-' + document.getElementById("gosb").value
        + '-' + document.getElementById("timeat").value
        + '-' + document.getElementById("stopsb").value;
    });
    
    function FormatNumber(x) {
        if (typeof x === "undefined") {
            return '';
        } else {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' VNĐ';
        }
    };
    ///,|VNĐ|\s/g
    function UnFormatNumber(x) {
        if (typeof x === "undefined") {
            return '';
        } else {
        return x.toString().replace(/,|VNĐ|\s/g, "");
        }
    };
    
    $('#sumMoney').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#sumMoney").blur(function() {
        document.getElementById("sumMoney_fake").value = UnFormatNumber($('#sumMoney').val());
    });
    
    $("#customersName").on('blur',function() {
            var temx='';
            var xtem = $.trim($('#customersName').val().toUpperCase());
            xtem = xtem.replace(/[^a-zA-Z-\r\n-\n\r-\r-\n-\s]/g,"");
            xtem = xtem.replace(/\r\n|\n\r|\r|\n/g,"-");

            var arr_name = xtem.split('-');
            for(i=0;i<arr_name.length;i++)
            {
                    var xx=$.trim(arr_name[i]);
                    if (xx=='')
                    {
                            arr_name.splice(i,1);
                            i=i-1;
                    }	
            }
            document.getElementById("customersName_fake").value = xtem;
    });
    
    $("#booking_place_code").keyup(function() {
        $(this).val($(this).val().replace(/([a-z])/,function(s){return s.toUpperCase()}));
    });
    
    $("#ajaxform").submit(function(e)
        {
            if($('#booking_place_code').val().trim() == ""){
                alert("Nhập mã đặt chỗ!");$(this).focus();return false;
            }
            if($('#customersName').val().trim() == ""){
                alert("Nhập tên khách hàng!");$(this).focus();return false;
            }
            
            if($('#datefly').val().trim() == ""){
                alert("Nhập ngày bay!");$(this).focus();return false;
            }
            if($('#numberfly').val().trim() == ""){
                alert("Nhập số hiệu chuyến bay!");$(this).focus();return false;
            }
            if($('#gosb').val().trim() == ""){
                alert("Nhập nơi đi!");$(this).focus();return false;
            }
            if($('#timefly').val().trim() == ""){
                alert("Nhập thời gian đi!");$(this).focus();return false;
            }
            if($('#stopsb').val().trim() == ""){
                alert("Nhập nơi đến!");$(this).focus();return false;
            }
            if($('#timeat').val().trim() == ""){
                alert("Nhập thời gian đến!");$(this).focus();return false;
            }
        });
    
});
</script>